<template>
	<view class="">
		<view class="fixed z-16" style="width: 100%;">
			<!-- 头像 -->
			<view class="flex items-center m-20r">
				<view class="flex-1">
					<image class=" h-100r w-100r rounded-50r" :src="avatar" mode="aspectFill"></image>
				</view>

				<view class="flex-4 flex flex-col">
					<text class="text-40r font-600 main-color">{{nickname}}</text>
					<text class="text-20r">未设置签名</text>
				</view>
				<view v-if="!myself" class="flex-1">
					<view @click="follow" class="w-140r flex items-center flex-center h-60r rounded-15r main-bg-color">
						<text class="text-30r" style="color: #fff;">{{isFollowed?'取消关注':'关注'}}</text>
					</view>
				</view>
			</view>
			<!-- 头像 结束-->

			<!-- 获赞 动态数 关注数 粉丝数 -->
			<view class="flex items-center justify-around">
				<view class="flex flex-col items-center">
					<text class="secondy-color font-bold">{{work_num}}</text>
					<text class="text-20r text-main">作品数</text>
				</view>
				<view class="flex flex-col items-center">
					<text class="secondy-color font-bold">{{dynamic_mum}}</text>
					<text class="text-20r text-main">动态数</text>
				</view>
				<view class="flex flex-col items-center">
					<text class="secondy-color font-bold">{{follow_num}}</text>
					<text class="text-20r text-main">关注数</text>
				</view>
				<view class="flex flex-col items-center">
					<text class="secondy-color font-bold">{{fans_num}}</text>
					<text class="text-20r text-main">粉丝数</text>
				</view>
			</view>


			<!-- 获赞 动态数 关注数 粉丝数 结束-->

			<!-- 顶部导航栏开始 -->
			<view class="mt-20r" style="width: 100%;">
				<view class="flex h-60r">

					<view class="flex-4 flex justify-around items-center">
						<view class="text-30r font-bold" :class="[curTabIndex==0 ? 'activated' : '']"
							@click="clikeTabNav(0)">动态</view>
						<view class="text-30r font-bold" :class="[curTabIndex==1 ? 'activated' : '']"
							@click="clikeTabNav(1)">作品</view>

					</view>
				</view>
			</view>

			<!-- 顶部导航栏结束 -->
		</view>
		<!-- 占位 -->
		<view class="h-300r"></view>




		<!-- 动态、作品集 开始-->
		<view class="">
			<swiper class="swiper" style="height: calc(100vh - 400rpx);" :current="curTabIndex" @change="swiperChange">
				<swiper-item>
					<!-- 动态 开始 -->
					<scroll-view scroll-y="true" style="height: 100%; background-color: #E5E5E5;">
						<view v-for="(item,index) in data.dynamics" :key="index" class="p-10r mb-20r"
							style="border-bottom: 2rpx solid #E5E5E5 ; background-color: #fff;">
							<!-- 动态顶部 -->
							<view
								class="pb-5r flex items-center border-solid border-top-0 border-right-0 border-left-0 border-bottom-2r"
								:style="{'border-color':this.theme.thirdColor}">
								<!-- 头像 -->
								<view class="flex-1">
									<image :src="avatar" class="w-100r h-100r rounded-50r mr-15r ml-15r"
										style="background-color: aqua;" mode="aspectFill"></image>
								</view>
								<view class="flex flex-col flex-3">
									<text class="text-36r font-600">{{nickname}}</text>
									<text class="text-20r">{{vk.pubfn.dateDiff(item._add_time)}}</text>
								</view>
								<!-- 头像结束 -->

								<!-- 浏览 转发量 -->
								<view class="flex flex-1 items-center justify-around">
									<view class="flex items-center">
										<text class="mr-10r text-40r iconfont icon-fire" style="color: red;"></text>
										<text class="text-main">{{item.view_count}}</text>
									</view>
									<!-- 									<view class="flex items-center">
										<text class="text-50r iconfont icon-fenxiang1"></text>
										<text>10000</text>
									</view> -->
								</view>
								<!-- 浏览 转发量 结束 -->
							</view>
							<!-- 动态顶部 结束-->

							<!-- 内容部分 -->
							<view @click="itemClick(item,index)" class="pl-10r pr-10r">
								<text class="lines-2 truncate pt-10r mb-10r">{{item.content}}</text>
								<view v-if="item.dynamic_banner_imgs.length > 1" class="flex justify-around">
									<image class="w-360r h-360r rounded-15r mr-5r" :src="item.dynamic_banner_imgs[0]"
										mode="aspectFill">
									</image>
									<image class="w-360r h-360r rounded-15r ml-5r" :src="item.dynamic_banner_imgs[1]"
										mode="aspectFill">
									</image>
								</view>
								<view v-else class="flex justify-around">
									<image class="w-700r h-700r rounded-15r mr-5r" :src="item.dynamic_banner_imgs[0]"
										mode="aspectFill">
									</image>
								</view>
							</view>
							<!-- 内容部分 结束 -->


						</view>

					</scroll-view>


				</swiper-item>
				<swiper-item>
					<scroll-view scroll-y="true" style="height: 100%; background-color: #E5E5E5;">
						<view class="pl-20r pr-20r flex flex-wrap justify-between">
							<view v-for="(item,index) in data.works" :key="index" @click="itemClick(item,index)"
								class="mt-10r mb-10r p-10r w-330r rounded-20r flex flex-col items-center"
								style="background-color: #fff;">
								<image class="w-330r h-330r rounded-20r " :src="item.cloth_imgs[0]"
									mode="aspectFill">
								</image>
								<view class="main-color text-20r">{{"《"+item.name+"》"}}</view>
								<!-- <view class="self-start flex items-center justify-between" style="width: 100%;">
									<view class="flex items-center">
										<image :src="item.publisher.avatar" class=" mr-10r w-70r h-70r rounded-35r"
											mode="aspectFill"></image>
										<text
											class="text-30r">{{item.publisher.nickname.length>10 ? item.publisher.nickname.substr(0,10) + '...' : item.publisher.nickname}}</text>
									</view>
									<view class="">
										<text class="iconfont icon-dingwei"></text>
										<text class="text-25r">34米</text>
									</view>
								</view> -->

							</view>
						</view>



					</scroll-view>
				</swiper-item>
			</swiper>
		</view>
		<!-- 动态、作品集 结束-->

	</view>
</template>

<script>
	export default {
		data() {
			return {
				avatar: '../../static/images/默认头像.png',
				nickname: '加载中',
				isFollowed: false,
				curTabIndex: 0,
				myself: false,
				work_num:0,
				dynamic_mum:0,
				follow_num:0,
				fans_num:0,
				data: {}

			};
		},
		onLoad(options = {}) {
			if (vk.getVuex('$user.userInfo._id') == options.id) {
				this.myself = true;
			}
			console.log(options.id);
			vk.callFunction({
				url: 'client/dynamic/kh/getMyDynamic',
				title: '加载中...',
				data: {
					userId: options.id
				}
			}).then((r) => {
				this.data = r.data;
				console.log('主页动态数据是：' + this.data.dynamics[0]._id);
				this.avatar = this.data.userData.avatar || this.avatar;
				this.nickname = this.data.userData.nickname || this.nickname;
				this.isFollowed = this.data.isFollowed;
				this.work_num = this.data.works.length;
				this.dynamic_mum = this.data.dynamics.length;
				this.follow_num = this.data.follow_num;
				this.fans_num = this.data.fans_num;
				// this.trigger = false;
			});
		},
		methods: {
			follow() {
				if (!this.isFollowed) {
					vk.callFunction({
						url: 'client/follow/kh/addFollower',
						title: '加载中...',
						data: {
							userId: this.data.userData._id
						}
					}).then((r) => {
						vk.toast('关注成功');
						this.isFollowed = !this.isFollowed;
						this.fans_num = this.fans_num+1;
						// this.trigger = false;
					});
				} else {
					vk.callFunction({
						url: 'client/follow/kh/delFollower',
						title: '加载中...',
						data: {
							userId: this.data.userData._id
						}
					}).then((r) => {
						vk.toast('取消关注成功');
						this.isFollowed = !this.isFollowed;
						this.fans_num = this.fans_num-1;
						// this.trigger = false;
					});
				}


			},
			// 点击tab导航
			clikeTabNav(e) {
				let newIndex = parseInt(e);
				if (newIndex === this.curTabIndex) {
					return;
				}
				this.curTabIndex = newIndex;
			},
			swiperChange(e) {
				// console.log(e);
				this.curTabIndex = e.detail.current;

			},
			itemClick(item,index){
				vk.navigateTo({
					url: '/pages/dynamic-detail/dynamic-detail?id=' + item._id
				})
			}
		}
	}
</script>

<style lang="scss">
	// page{
	// 	background-color: var(--third-color);
	// }
	.activated {
		color: var(--main-color);
		border-bottom: solid var(--main-color) 2rpx;
	}
</style>
